package com.crm.dao.client;

import com.crm.pojo.ClientInfo;
import com.crm.vo.ClientContactVO;
import com.crm.vo.ClientGroupCountVo;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.math.BigDecimal;
import java.util.List;

public interface ClientInfoDao extends CrudRepository<ClientInfo, Long>, JpaSpecificationExecutor<ClientInfo> {

	/**
	 * 根据用户编号查找所有客户
	 * @param userId
	 * @return
	 */
    @Query("from ClientInfo c where c.clientInfoIsDel != '是' and c.userId = ?1 ")
    public List<ClientInfo> findAllNotDelByUserId(BigDecimal userId);
    
    /**
     * 查找所有客户
     * @return
     */
    @Query("from ClientInfo c where c.clientInfoIsDel != '是' ")
    public List<ClientInfo> findAllNotDel();
    
    
    /**
     * 根据客户姓名查找所有客户
     * @param cname
     * @return
     */
    @Query("from ClientInfo c where c.clientInfoIsDel != '是' and c.cname = ?1")
    public List<ClientInfo> findClintInfoByCname(String cname);

    /**
     * 根据客户编号查找所有客户
     * @param cid
     * @return
     */
    @Query("from ClientInfo c where  c.cid = ?1")
    public ClientInfo findClientInfoByCid(Long cid);

    /**
     * 根据客户编号查询客户和联系人
     * @param cid
     * @return
     */
    @Query("select new com.crm.vo.ClientContactVO(client,contact) from Contact contact,ClientInfo client "
    		+ "where contact.clientInfo=client and client.cid=?1 and client.clientInfoIsDel != '是'")
    public List<ClientContactVO> getClientContactList(Long cid);

    /**
     * 根据供应商姓名模糊查找所有供应商
     */
    @Query("from ClientInfo c where c.clientInfoIsDel != '是' and c.cname like ?1")
    public List<ClientInfo> findClintInfoBymh(String q);
    
}
